package com.ruoyi.web.controller.caochong;


import com.ruoyi.web.domain.Comment;
import com.ruoyi.web.service.caochongService.CommentService;
import com.ruoyi.web.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 曹冲
 * @since 2022-11-05
 */
@Slf4j
@RestController
@RequestMapping("/web/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;



    //查询所有评论
    @GetMapping
    public R getAll(){
        ArrayList<Comment> comments = new ArrayList<>();
        List<Comment> list = commentService.lambdaQuery().list();
        comments.addAll(list);

        return  R.ok(comments);

    }

    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id){
        Comment one = commentService.lambdaQuery().eq(Comment::getId, id).one();
        return R.ok(one);
    }

}

